<?
class Fibonacci implements Iterator
{
    public $prev1 = 1;
    public $prev2 = 0;
    public $count_ = 0;

    public function rewind() {
        $this->prev1 = 1;
        $this->prev2 = 0;
        $this->count_ = 0;
    }

    public function current() {
        return $this->prev2;
    }

    public function key() {
        return $this->count_;
    }

    public function next() {
        $toReturn = $this->prev2;
        $temp = $this->prev1 + $this->prev2;

        $this->prev2 = $this->prev1;
        $this->prev1 = $temp;

        $this->count_ += 1;
        return $toReturn;
    }

    public function valid() {
        return true;
    }
}

$fib = new Fibonacci();

for ($x = 0; $x < ((int)$argv[1]) + 1; $x += 1) {
    print $fib->next() . " ";
}
print "...\n";
?>
